@extends('admin.base')

@section('title') 添加电影信息页面 @endsection

@section('caption')
    添加电影信息页面
@endsection

@section('content')

    <form class="form-horizontal" action="articleinsert">
        <div class="col-md-6">
            <div class="form-group">
                <label class="control-label col-md-2 text-right">文章标题</label>
                <div class="col-md-10">
                    <input name="title" value="{{isset($article)?$article->title:''}}" type="text" class="form-control">
                    <input name="id" value="{{isset($article)?$article->id:0}}" type="hidden" class="form-control" >
                </div>
            </div>


            <div class="form-group">
                <label class="control-label col-md-2 text-right">文章类型</label>
                <div class="col-md-10">
                    <select name="type" class="form-control">
                        @foreach($types as $type)
                            <option value="{{$type->id}}">{{$type->name}}</option>
                        @endforeach
                    </select>
                </div>
            </div>


            <div class="row">
                <div class="form-group">
                    <label class="control-label col-md-2 text-right">文章封面</label>
                    <div class="col-lg-5">
                        <input type="file" class="file-styled" name="cover" value="{{asset("/")}}{{isset($article)?$article->cover:''}}">
                    </div>
                    @if(isset($article)?$article:'')
                        <div class="col-lg-5">
                            <img src="/{{isset($article)?$article->cover:''}}" height="100px" width="300px">
                        </div>
                </div>
                @endif()
            </div>

            <div class="form-group">
                <label class="control-label col-md-2 text-right">作者</label>
                <div class="col-md-10">
                    <input name="author" value="{{isset($article)?$article->author:''}}" type="text"
                           class="form-control">
                </div>
            </div>


            <div class="form-group">
                <label class="control-label col-md-2 text-right">内容</label>
                <div class="col-md-10">
                    <div id="editor" data-content="">{!! isset($article)?$article->content:'' !!}</div>
                    <textarea hidden id="content" name="content">{{isset($article)?$article->content:''}}</textarea>
                </div>
            </div>
        </div>


        <div class="col-xs-12 no-padding">
            <div class="col-md-6">
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <button type="submit" class="btn btn-primary pr-20 pl-20 mr-10">提交</button>
                        <button type="reset" class="btn btn-default pr-20 pl-20 ml-10">清空</button>
                    </div>
                </div>
            </div>
        </div>
    </form>

@endsection

@section('after')
    <script src="{{asset('libs/js/core/wangeditor.js')}}"></script>
    <script type="text/javascript">

        const E = window.wangEditor
        const editor = new E('#editor')
        const $text1 = $('#content')
        editor.config.onchange = function (html) {
            // 第二步，监控变化，同步更新到 textarea
            $text1.val(html)
        }

        //自定义 fileName
        editor.config.uploadFileName = 'article_file'

        // 配置 server 接口地址
        editor.config.uploadImgServer = '{{url('admin/article/ar_file')}}'

        //编辑器高度
        editor.config.height = 600

        editor.create()
        $text1.val(editor.txt.html())
    </script>

@endsection
